package com.shanghaiyimu.yimiyangche.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.activity.KeHuJingLiActivity;
import com.shanghaiyimu.yimiyangche.activity.LoginActivity;
import com.shanghaiyimu.yimiyangche.activity.PenqiActivity;
import com.shanghaiyimu.yimiyangche.activity.QuanBudingdanActivity;


/**
 * A simple {@link Fragment} subclass.
 */
public class KehuFragment extends Fragment {

    private TextView login,kehujingli;
    private int CODE = 0;
    private TextView quanbudingdan;
    private ImageView penqi;
    public KehuFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_kehu, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        penqi = (ImageView) view.findViewById(R.id.penqiyemian);
        penqi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(),PenqiActivity.class));
            }
        });
        quanbudingdan = (TextView) view.findViewById(R.id.dingdan);
        quanbudingdan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(), QuanBudingdanActivity.class));
            }
        });

        login = (TextView) view.findViewById(R.id.name_text);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), LoginActivity.class);
                startActivityForResult(intent,CODE);
            }
        });
        kehujingli = (TextView) view.findViewById(R.id.kehujingli);

        kehujingli.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(),KeHuJingLiActivity.class));
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        String name = data.getExtras().getString("name");
        switch (resultCode){
            case 0:
                login.setText(name);
                break;
            default:
                break;
        }
    }
}
